// ==UserScript==
// @name         GitHub SOCKS Proxy
// @namespace    http://your.namespace/
// @version      0.1
// @description  Use SOCKS proxy when accessing GitHub
// @author       You
// @match        https://github.com/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function () {
    'use strict';

    const socksProxyHost = '127.0.0.1';
    const socksProxyPort = 1080;

    function requestWithSocksProxy(details) {
        details.proxy = `socks://${socksProxyHost}:${socksProxyPort}`;
        GM_xmlhttpRequest(details);
    }

    const originalFetch = window.fetch;
    window.fetch = function (input, init) {
        return originalFetch(input, init);
    };

    const originalXMLHttpRequest = window.XMLHttpRequest;
    window.XMLHttpRequest = function () {
        const xhr = new originalXMLHttpRequest();
        xhr.open = function () {
            xhr.proxy = `socks://${socksProxyHost}:${socksProxyPort}`;
            return originalXMLHttpRequest.prototype.open.apply(xhr, arguments);
        };
        return xhr;
    };


    const originalImage = window.Image;
    window.Image = function () {
        const img = new originalImage();
        img.proxy = `socks://${socksProxyHost}:${socksProxyPort}`;
        return img;
    };


})();
